<template>
	<view class="RecordVideo" :style="{ height: webStyle.height }">
		<view class="browseVideo">
			<video class="video" object-fit="contain" :src="successRes.tempVideoPath" controls></video>
		</view>
		<view class="main-btn" @tap="comfirm">确认</view>
	</view>
</template>

<script>
import { tools } from "../../utils/util";
import * as api from "@/api/home.js";
export default {
	name: "RecordVideo",
	data() {
		return {
			imgPath: tools.imgPath,
			inf0Pt: 0,
			systemInfo: {},
			webStyle: {
				height: ""
			},
			type: 1,
			isRecord: false,
			cameraContext: null,
			successRes: {}
		};
	},
	methods: {
		// 数据初始化
		initRes() {
			let successRes = null;
			["tempRecordVideoRes1", "tempRecordVideoRes2", "tempRecordVideoRes3"].map((e, i) => {
				if (!successRes) {
					let res = uni.getStorageSync(e);
					if (!res) return;
					this.type = i + 1;
					successRes = res;
					uni.removeStorageSync(e);
				}
			});
			this.successRes = successRes || {};
		},

		// 获取系统info
		initSystemInfo(isUpdate = true) {
			const that = this;
			return new Promise((resolve, reject) => {
				uni.getSystemInfo({
					success(payload) {
						if (isUpdate) {
							that.systemInfo = payload;
							that.webStyle.height = `${that.systemInfo.windowHeight}px`;
							console.log("initSystemInfo", that.systemInfo);
							console.log("initSystemInfo132", that.systemInfo.uniPlatform);
							switch (that.systemInfo.uniPlatform) {
								case "web":
									that.inf0Pt = 4.5;
									break;
								case "app":
									that.inf0Pt = 4.5;
									break;
								case "mp-weixin":
									that.inf0Pt = 9.6;
									break;
							}
						}
						resolve(payload);
					}
				});
			});
		},

		// 跳转页面
		toPage(path, type = "navigateTo") {
			uni[type]({
				url: path
			});
		},

		// 回退
		back() {
			let pages = getCurrentPages();
			if (pages.length > 1) {
				uni.navigateBack({
					delta: 1
				});
			} else {
				uni.setStorageSync("toHome", {
					footerBarListAc: 2
				});
				uni.reLaunch({
					url: "/pages/MakeAvatar/MakeAvatar"
				});
			}
		},

		// 确定
		comfirm() {
			uni.setStorageSync("tempRecordVideoRes" + this.type, this.successRes);
			let pages = getCurrentPages();
			let MakeAvatarPageInd = -1;
			for (let i = 0; i < pages.length; i++) {
				if (pages[i].route == "pages/MakeAvatar/MakeAvatar") {
					MakeAvatarPageInd = i + 1;
				}
			}
			if (MakeAvatarPageInd != -1) {
				uni.navigateBack({
					delta: pages.length - MakeAvatarPageInd
				});
			} else {
				this.back();
			}
		}
	},
	onLoad() {
		this.initSystemInfo();
		this.initRes();
	}
};
</script>

<style lang="scss">
.RecordVideo {
	background: #000;
	display: flex;
	flex-direction: column;
	.browseVideo {
		flex: 1;
		box-sizing: border-box;
		width: 100%;
		padding: 5vw;
		.video {
			width: 100%;
			height: 100%;
			border-radius: 2.5vw;
		}
	}
	.main-btn {
		display: flex;
		justify-content: center;
		align-items: center;
		background: linear-gradient(180deg, #6edc9a 0%, #05ecbd 100%);
		width: 90%;
		height: 15vw;
		margin: 5.2vw auto;
		border-radius: 2.5vw;
		color: #000;
		font-weight: bold;
	}
}
</style>
